import type { GoogleElements } from '../../../../../../../../types/constants/personalization/google'
import { ThemeVarService } from '../../../../../../../../lib/abstract/style/theme_var/service'
import { PAGE_ELEMENTS, SUPPORTED_PLATFORMS } from '../../../../../../../../types/constants'
import { SearchCommonStyles } from '../../common'

export class GoogleBooksPage {
  elements: GoogleElements = PAGE_ELEMENTS[SUPPORTED_PLATFORMS.GOOGLE]
  private static instance: GoogleBooksPage
  private readonly themeVarService: ThemeVarService = ThemeVarService.getInstance()
  private readonly searchCommonStyles: SearchCommonStyles = SearchCommonStyles.getInstance()

  /**
   * 获取单例实例
   */
  public static getInstance(): GoogleBooksPage {
    if (!GoogleBooksPage.instance) {
      GoogleBooksPage.instance = new GoogleBooksPage()
    }
    return GoogleBooksPage.instance
  }

  init(): void {
  }

  /**
   * 无搜索结果样式
   */
  noSearchResult(): string {
    return ``
  }

  getMainStyles(): string {
    return `
  #main {
    #rcnt {
      padding-top: ${this.themeVarService.search.resultItem.gap} !important;
      padding-bottom: ${this.themeVarService.search.resultItem.gap} !important;

      > div {
        display: block !important;
        margin: 0 !important;
      }
      
      #search {
        /* 搜索结果列表 */
        #rso {
          ${this.searchCommonStyles.resultContainerStyles({ fullWidth: false })}
          
          /* 结果项 */
          > div {
            ${this.searchCommonStyles.resultItemStyles({ overflowHide: false, noMarginBottom: true })}
            padding-bottom: 0 !important;
            
            a {
              &:hover {
                h3 {
                  color: var(${this.themeVarService.link.default.textHover}) !important;
                  text-decoration: none !important;
                }
              }

              /* 标题 */
              h3 {
                color: var(${this.themeVarService.link.default.text}) !important;
                
                &:hover {
                  color: var(${this.themeVarService.link.default.textHover}) !important;
                  text-decoration: none !important;
                }
              }
            }
            
            > div > div > div:has(cite) {
              /* 链接 */
              > div:nth-child(1) {
                cite {
                  color: var(${this.themeVarService.search.default.textNeutral}) !important;
                }
              }

              /* 元数据 */
              > div:nth-child(2) {
                color: var(${this.themeVarService.search.default.text}) !important;
                a {
                  color: var(${this.themeVarService.link.default.text}) !important;
                }
              }
              
              /* 描述 */
              > div:nth-child(3) {
                border: none !important;
                color: var(${this.themeVarService.search.default.text}) !important;
                
                span {
                  color: var(${this.themeVarService.search.default.text}) !important;
                  
                  em {
                    color: var(${this.themeVarService.em.text}) !important;
                  }
                }
              }
            }
          }
        } 
      }
    }
  }
    `
  }
}
